//
//  UIColor+WLStatusBarStyle.m
//  xiacai_ios_v6
//
//  Created by 王亮 on 2018/5/23.
//  Copyright © 2018年 王振标. All rights reserved.
//

#import "UIColor+WLStatusBarStyle.h"
#import "UIImage+WLImgColor.h"

@implementation UIColor (WLStatusBarStyle)
//获取导航栏主题
+(UIStatusBarStyle)captureWithView:(UIView *)view{
    // 创建一个context
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(view.frame.size.width, [[UIApplication sharedApplication] statusBarFrame].size.height), NO, [UIScreen mainScreen].scale);
    //把当前的全部画面导入到栈顶context中并进行渲染
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    // 从当前context中创建一个新图片
    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
    // 使当前的context出堆栈
    UIGraphicsEndImageContext();
    
    
    /** 获取状态栏区域颜色 */
    UIColor *navColor = img.mostColor;
    NSLog(@"%@",navColor);
    CGFloat red = 0.0;
    CGFloat green = 0.0;
    CGFloat blue = 0.0;
    CGFloat alpha = 0.0;
    
    [navColor getRed:&red green:&green blue:&blue alpha:&alpha];
    
    if (alpha == 0){
        return UIStatusBarStyleDefault;
    }
    else if (red >= 0.5f || green >= 0.5f || blue >= 0.5f){
        //        statusBar_white_WL;
        return UIStatusBarStyleDefault;
    }
    else{
        //        statusBar_black_WL;
        return UIStatusBarStyleLightContent;
    }
}

@end
